﻿using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;

namespace BitTorrentSharp.Client
{
	using Peers;

	/// <summary>
	/// Helper class for convert between message and raw messages. This class is a static class.
	/// </summary>
	public static class MessageConvertHelper
	{
		/// <summary>
		/// Convert a peer message to a raw message.
		/// </summary>
		/// <param name="message">The <see cref="PeerMessage"/> to be converted.</param>
		/// <returns>The <see cref="RawMessage"/> got.</returns>
		public static RawMessage ToRawMessage(this PeerMessage message)
		{
			if (message == null)
			{
				throw new ArgumentNullException("message");
			}

			return new RawMessage(message.GetBytes());
		}

		/// <summary>
		/// Convert a raw message to a peer message.
		/// </summary>
		/// <param name="message">The <see cref="RawMessage"/> to be conveted.</param>
		/// <returns>The <see cref="PeerMessage"/> got.</returns>
		public static PeerMessage ToPeerMessage(this RawMessage message)
		{
			throw new NotImplementedException();
		}

		private static PeerMessage ToPeerMessageCore(this RawMessage message)
		{
			// zero-length is a keep-alive message.
			if (message.Length == 0)
			{
				return new PeerKeepAliveMessage();
			}

			throw new NotImplementedException();
		}
	}
}
